<template>
  <el-dialog
    v-el-drag-dialog
    title="支付明细"
    :visible.sync="visible"
    width="600px"
    @close="reset"
  >
    <lb-table
      ref="lbTable"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      :immediate-fetch="false"
      @fetch="fetchData"
    />
  </el-dialog>
</template>

<script>
  import { queryOrderbillPayDetailList } from '@/api'
  import moment from 'dayjs'

  export default {
    name: 'pay-detail',
    props: {
      paymentMethodMap: {
        type: Array,
        required: true
      }
    },
    data() {
      return {
        visible: false,
        tableData: {
          total: 0,
          column: [
            {
              prop: '',
              label: '支付方式',
              render: (h, { row }) => <span>{ row.createUser }</span>
            },
            {
              prop: 'payFee',
              label: '金额',
              formatter: row => (row.payFee || row.payFee === 0) && Number(row.payFee).toFixed(2)
            },
            {
              prop: 'createTime',
              label: '支付时间',
              render: (h, { row }) => <span>{ row.createTime && moment(row.createTime).subtract(8, 'hour').format('YYYY-MM-DD HH:mm') }</span>
            }
          ],
          data: []
        }
      }
    },
    methods: {
      async open(temp) {
        this.fetchData(temp)
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
        })
      },
      async fetchData(temp) {
        const query = {
          orderCode: temp.orderCode
        }
        const res = await queryOrderbillPayDetailList(query)
        this.tableData.data = res.data
      },
      reset() {
        this.tableData.data = []
      }
    }
  }
</script>

<style scoped>

</style>
